package main

import (
	"fmt"
)

type Person interface {
	Name() string
}

// 接口组合
type Teacher interface {
	Person //接口组合
	Teach()
}
type MyTeacher struct {
	name  string
	class string
}

func (t MyTeacher) Name() string {
	return t.name
}
func (t MyTeacher) Teach() {
	fmt.Println("I am teaching ", t.class)
}
func say_hello(p Person) {
	if m, ok := p.(MyTeacher); ok { //看此Person是否为MyTeacher的实例，如果是再执行if内的内容
		fmt.Println("hello ", m.name)
	}
}

func say_hello2(p *MyTeacher) {

}
func main() {
	var t Teacher = MyTeacher{
		name:  "roc",
		class: "english",
	}

	fmt.Println(t.Name()) //roc
	t.Teach()             //I am teaching english
	say_hello(t)          //hello roc

	//	say_hello2(t) //hello roc
	//	if m, ok := t.(MyTeacher); ok {
	//		fmt.Println("hello ", m.Name())
	//	}

}
